import Vue from 'vue';
import Router from 'vue-router';

import Layout from '@/layout' // Layout

Vue.use(Router);

export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index')
            }
        ]
    },
    {
        path: '/login',
        meta: {title: '登录'},
        component: () => import('../views/login/login.vue'),
        hidden: true
    },
    {
        path: '/error/:code',
        name: 'error',
        meta: {
            title: 'error'
        },
        component: () => import('../views/error/index'),
        hidden: true
    },
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            name: '系统首页',
            component: () => import('../views/dashboard/Dashboard.vue'),
            meta: {
                icon: 'home-2',
                title: '系统首页', requireAuth: true
            }
        }]
    },
    {
        path: '/data',
        component: Layout,
        name: '数据管理',
        meta: {
            title: '数据管理',
            icon: 'list'
        },
        children: [{
            path: 'icon',
            name: '图标管理',
            component: () => import('../views/data/icon/Icon.vue'),
            meta: {
                icon: 'icon',
                title: '图标管理', requireAuth: true
            }
        }, {
                path: 'drugs',
                name: '药品管理',
                component: () => import('../views/data/drugs/index.vue'),
                meta: {
                    icon: 'skill',
                    title: '药品管理', requireAuth: true
                }
            },
            {
                path: 'news',
                name: '新闻管理',
                component: () => import('../views/data/news/index.vue'),
                meta: {
                    icon: 'international',
                    title: '新闻管理', requireAuth: true
                }
            },
            {
                path: 'update/?id',
                hidden:true,
                component: () => import('../views/data/news/UpdateForm.vue'),
                meta: {
                    title: '编辑新闻',
                }
            },


        ]
    },
    {
        path: '/user',
        component: Layout,
        name: '用户管理',
        meta: {icon: 'users', title: '用户管理'},
        children: [
            {
                path: 'patient',
                name: '病患管理',
                component: () => import('../views/User/patient/tb_patient.vue'),
                meta: {icon: 'people', title: '病患管理'}
            },
            {
                path: 'doctor',
                name: '医生管理',
                component: () => import('../views/User/doctor/tb_doctor'),
                meta: {icon: 'user', title: '医生管理'}
            },
            {
                path: 'authority',
                name: '权限管理',
                component: () => import('../views/User/user/tb_user'),
                meta: {icon: 'lock', title: '权限管理'}
            }
        ]
    },
    {
        path: '/info',
        component: Layout,
        children:
            [{
                path: 'info',
                name: '消息通知',
                component: () => import('../views/note/info.vue'),
                meta: {
                    icon: 'message',
                    title: '消息通知'
                }
            }]

    }
    ,
    {
        path: '/form',
        component: Layout,
        children: [{
                path: 'form',
                name: '预约挂号',
                component: () => import('../views/appoint/index.vue'),
                meta: {
                    icon: 'documentation',
                    title: '预约挂号'
                }
            },]
    }  ,
    {
        path: '/subject',
        component: Layout,
        children: [{
                path: 'subject',
                name: '科室管理',
                component: () => import('../views/subject/index.vue'),
                meta: {
                    icon: 'tree',
                    title: '科室管理'
                }
            },]
    }
    ,
    {
        path: '/editor',
        component:
        Layout,
        children:
            [{
                path: 'editor',
                name: '留言管理',
                component: () => import('../views/message/VueEditor.vue'),
                meta: {
                    icon: 'mail',
                    title: '留言管理'
                }
            }]
    }
    ,
    /* {
         // markdown组件
         path: '/markdown',
         component: () => import('../views/Markdown.vue'),
         meta: { title: 'markdown编辑器' }
     },
     {
         // 图片上传组件
         path: '/upload',
         component: () => import('../views/Upload.vue'),
         meta: { title: '文件上传' }
     },
     {
         // vue-schart组件
         path: '/charts',
         component: () => import('../views/BaseCharts.vue'),
         meta: { title: 'schart图表' }
     },
     {
         // 拖拽Dialog组件
         path: '/dialog',
         component: () => import('../views/DragDialog.vue'),
         meta: { title: '拖拽弹框' }
     },*/
// {
//     // 国际化组件
//     path: '/i18n',
//     component: Layout,
//     children: [{
//         path: 'i18n',
//         name: '国际化',
//         component: () => import('../views/I18n.vue'),
//         meta: {
//             icon: 'international',
//             title: '国际化'
//         }
//     }]
// },
    {
        // 权限页面
        path: '/permission',
        component:
        Layout,
        children:
            [{
                path: 'permission',
                name: '权限设置',
                component: () => import('../views/authority/Permission.vue'),
                meta: {
                    icon: 'lock',
                    title: '权限设置', permission: true
                }
            }]

    }
//,
// {path: '*', redirect: '/404'}
]

const createRouter = () => new Router({
    mode: 'history',
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes
})

const router = createRouter()

export function resetRouter () {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
